import request from '@/utils/request' // Assuming you have a request utility

/**
 * Generate questions based on parameters
 * @param {Object} params - Parameters for question generation
 * @param {string} params.subject - Subject/topic for questions
 * @param {string} [params.difficulty] - Difficulty level (easy/medium/hard)
 * @param {string} [params.type] - Question type (multiple_choice/short_answer/etc)
 * @param {number} [params.count=5] - Number of questions to generate
 * @param {string} [params.language='cn'] - Language for questions
 * @returns {Promise} Promise object representing the API response
 */
export function generateQuestion(params, options = {}) {
  const defaultData = {
    count: 5,
    language: 'cn',
    difficulty: 'medium',
    type: 'multiple_choice'
  }

  const data = {
    ...defaultData,
    ...params
  }

  return request({
    url: '/questions2/generator/generate',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json'
    },
    onDownloadProgress: options.onDownloadProgress
  })
}

// Optional: Add a function to get generation history
export function getGenerationHistory(page = 1, pageSize = 10) {
  return request({
    url: '/questions2/generator/history',
    method: 'get',
    params: {
      page,
      page_size: pageSize
    }
  })
}

// Optional: Add a function to save generated questions
export function saveGeneratedQuestions(questionIds) {
  return request({
    url: '/questions2/generator/save',
    method: 'post',
    data: {
      question_ids: questionIds
    }
  })
}
